// Sunghan Cho
// 301140084
// sunghanc@sfu.ca

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "itemmanager.h"
#include "itemlistmodel.h"

namespace Ui {
	class MainWindow;
}

/*
 * Main GUI for the application.
 * - Uses the ItemManager's for statistics updates.
 *   Note: Future improvement is to extract the statistics into a class.
 * - Uses the ItemListModel's for connecting to the table UI Widgets (custom)
 *
 * Code for setup and use:
 *      // ... declare ItemManagers and ItemListModels ...
 *      // Create class and initialize.
 *      MainWindow w(&courses, &students);
 *      w.setCourseListModel(pCourseModel, pSelectedStudentModel, pRepeatStudentModel);
 *
 * And, have other components listen for the addItemsFromFile signal:
 *      QObject::connect(&w, SIGNAL(addItemsFromFile(QString)),
 *                       &someQObj, SLOT(someSlot(QString)));
 *
 * by Brian Fraser, 2012
 */
class MainWindow : public QMainWindow
{
	Q_OBJECT

public:
	// Pass in the ItemManager pointers at construction so
	// it can update statistics when the ItemMangers change their items.
	explicit MainWindow(ItemManager *pCourses, ItemManager *pStudents, QWidget *parent = 0);
	~MainWindow();

	// Connect the GUI tables to ItemListModels (which provide data for the QTableViews).
	// Note: The 2 student models may be sub-classed from ItemListModel
	void setListModels(ItemListModel *pCourseModel, ItemListModel *pStudentModel, ItemListModel *pRepeatStudentModel);

signals:
	// Notify observers that the user has asked to add items to
	// the system from the file fileName.
	void addItemsFromFile(QString fileName);

private:
	// Calculate the total number of students.
	int countRepeatStudents();

private slots:
	// These slots are connected internally to UI widgets (buttons, ...)
	void updateStatistics();
	void clickedAddItems();
	void dumpModels();

private:
	Ui::MainWindow *ui;

	ItemManager *m_pCourses;
	ItemManager *m_pStudents;
};

#endif // MAINWINDOW_H
